VERSIONS = ["1.4.5", "1.4.7", "1.4.11"]
DEFAULT_VERSION = "1.4.11"
OLDER_VERSIONS = ["1.4.5", "1.4.7", "1.4.11"]
DEPENDS = ["zlib"]

def urlfunc( machine, directories, version ):
  """
  http://downloads.sourceforge.net/project/libpng/libpng14/older-releases/1.4.5/lpng145.zip
  http://downloads.sourceforge.net/project/libpng/libpng14/1.4.7/lpng147.zip
  """
  #URL_STR = "http://downloads.sourceforge.net/project/libpng/libpng%(SUB)s/%(OLDER)s%(VERSION)s/lpng%(SHORTVERSION)s.zip"
  URL_STR = "http://downloads.sourceforge.net/project/libpng/libpng%(SUB)s/%(OLDER)s%(VERSION)s/lpng%(SHORTVERSION)s.zip"
  return URL_STR % { "SUB" :version[0] + version[2] , "SHORTVERSION" : version.replace('.', ''),  "VERSION" : version, "OLDER" : "older-releases/" if version in OLDER_VERSIONS else "" }
URL = urlfunc


import os
from source.builders import CMakeBuilder

class PNGBuilder( CMakeBuilder ):
  """ subclass of ConfigureMakeBuilder with custom configure step """

  def configure( self ):
    zlibmod = self.dependencies["zlib"]
    zlibdir= zlibmod.getlibdir() 
    incdir = " -DZLIB_INCLUDE_DIR=" + zlibmod.getincludedir() 
    lib = " -DZLIB_LIBRARY="+ zlibdir +os.sep+("zlib.lib", "libz.so")[self.machine.isLinux()]
    CMakeBuilder.configure(self, incdir + lib)

BUILDER = PNGBuilder
